package com.ssyc.common.utils;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;

/**
 * 系统弹框的工具类
 * Created by Administrator on 2018/7/16 0016.
 */

public class AlertDialogUtil {

    /**
     * 两个回调 接口的方法(确定)
     *
     * @param context
     * @param content
     * @param listener
     */
    public static void showAlertDialog(Context context, String content, final onClickListener listener) {
        AlertDialog.Builder builder = new AlertDialog.Builder(context);
//        builder.setIcon(R.mipmap.ic_launcher);
        builder.setTitle("提示");
        builder.setMessage(content);//提示内容
        builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                if (listener != null) {
                    listener.onClickOk();
                }
            }
        });
        builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
            }
        });

        AlertDialog dialog = builder.create();
        dialog.show();
    }

    /**
     * 两个回调 接口的方法(确定)
     *
     * @param context
     * @param content
     * @param listener
     */
    public static void showAlertDialogTitle(Context context, String content, String title, final onClickListener listener) {
        AlertDialog.Builder builder = new AlertDialog.Builder(context);
//        builder.setIcon(R.mipmap.ic_launcher);
        builder.setTitle(title);
        builder.setMessage(content);//提示内容
        builder.setPositiveButton("交卷", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                if (listener != null) {
                    listener.onClickOk();
                }
            }
        });
        builder.setNegativeButton("不交卷", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
            }
        });

        AlertDialog dialog = builder.create();
        dialog.show();
    }


    /**
     * 两个回调 接口的方法(确定和取消)
     *
     * @param isCancel 是否允许取消
     * @param context
     * @param content
     * @param listener
     */
    public static void showAlertDialog(boolean isCancel, Context context, String content, final onListener listener) {
        AlertDialog.Builder builder = new AlertDialog.Builder(context);
        builder.setCancelable(isCancel);
        builder.setTitle("提示");
        builder.setMessage(content);//提示内容
        builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                if (listener != null) {
                    listener.onClickOk();
                }
            }
        });
        builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                if (listener != null) {
                    listener.onClickDismiss();
                }
            }
        });

        AlertDialog dialog = builder.create();
        dialog.setCanceledOnTouchOutside(isCancel);
        dialog.show();
    }

    /**
     * 回调接口
     */
    public interface onClickListener {
        //点击确定的接口
        void onClickOk();
    }


    /**
     * 包含点击取消和确定两个
     */

    public interface onListener {
        //点击确定的接口
        void onClickOk();

        //点击取消的接口
        void onClickDismiss();
    }


}
